<!doctype html>
<html>

<head>
	<title></title>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=0">
	<link rel="stylesheet" href="../res/css/weui.css" />
	<link rel="stylesheet" href="../res/css/weuix.css" />
	<link rel="stylesheet" href="../res/css/common.css" />
	<script src="../res/js/zepto.min.js"></script>
	<script src="../res/js/zepto.weui.js"></script>
	<script src="../res/js/common.js?v=2"></script>
	<style>
		#code {
			display: contents;
		}

		.cd {
			touch-action: none;
			width: 104px;
			height: 30px;
			border-radius: 30px;
			border: 1px solid #fc761f;
			color: #fc761f;
			background: #ffffff;
			float: right;
			margin-top: 10px;
		}

		.cd_pic {
			float: right;
			width: 104px;
			height: 40px;
			margin-top: 5px;
		}

		.disappear {
			display: none;
		}

		.weui-cell {
			display: block;
			position: relative;
			padding: 10px 15px;
		}

		.weui-btn_primary {
			background-color: #1189ff;
		}

		.weui-btn_primary:not(.weui-btn_disabled):active {
			color: rgba(255, 255, 255, 0.6);
			background-color: #1189ff;
		}

		.weui-cell__bd {
			height: 50px;
			line-height: 50px;
			border-bottom: 1px solid #E0E0E0;
		}

		.placeholder {
			background-image: url('https://zh.nxk520.com/HuLianWangYiLiao_Web/minImg/img_bg.png');
			background-size: 100% 100%;
			background-repeat: no-repeat;
			display: flex;
		}

		.placeholder img:first-child {
			margin: 0 auto;
			width: 40%;
			height: 30%;
			margin-top: 60px;
		}

		.placeholder img:last-child {
			margin: 0 auto;
			width: 50%;
			height: 75%;
			margin-top: 25px;
		}

		.left_img {
			width: 20px;
			height: 18px;
			display: inline-block;
			vertical-align: middle;
			z-index: 1;
		}

		.weui-input {
			padding-left: 10px;
			width: 80%;
		}

		#v_container {
			margin-top: 3px;
			width: 120px;
			height: 44px;
			line-height: 42px;
			display: inline-block;
			float: right;
			text-align: center;
			border-radius: 25px;
			background-color: #1189ff;
			color: #ffffff;
		}

		.notClickn {
			pointer-events: none;
			opacity: 0.5;
		}
	</style>
</head>

<body ontouchstart>
	<div class="fixed-top">
		<div class="weui-header" style="background-color: #ffffff;">
			<div class="weui-header-left"><a id="btnBack" onclick="goPage('inquiry_user_personal.htm');"
					class="icon icon-109"></a></div>
			<div class="weui-header-title">修改密码</div>
			<div class="weui-header-right"></div>
		</div>
	</div>
	<div class="weui-cells weui-cells_form">
		<div class="weui-cell">
			<div class="weui-cell__bd">
				<img src="../res/images/icon_user.png" class="left_img">
				<input class="weui-input" placeholder="请输入手机号码" class="weui_input" required id="txt_phone" type="tel"
					maxlength="11" oninput="check()">
			</div>
			<div class="weui-cell__bd" id="SMS">
				<img src="../res/images/icon_password.png" class="left_img">
				<input class="weui-input" placeholder="请输入验证码" class="weui_input" required id="code_input" type="text"
					style="width: 110px;">
				<div id="v_container" onclick="get_captcha()">发送验证码</div>
			</div>
			<div class="weui-cell__bd">
				<img src="../res/images/icon_password.png" class="left_img">
				<input class="weui-input" placeholder="请输入新登录密码" class="weui_input" required id="mewPass"
				type="password"
					onkeyup="value=value.replace(/[^\w\`\~\!\@\#\$\%\^\&\*\(\)\_\+\[\]\;\'\,\.\/\<\>\?\-\=\\]/ig,'')">
			</div>
			<div class="weui-cell__bd">
				<img src="../res/images/icon_password.png" class="left_img">
				<input class="weui-input" placeholder="再次确认新登录密码" class="weui_input" required id="mewPass_Again"
				type="password"
					onkeyup="value=value.replace(/[^\w\`\~\!\@\#\$\%\^\&\*\(\)\_\+\[\]\;\'\,\.\/\<\>\?\-\=\\]/ig,'')">
			</div>
			<a href="javascript:;" class="weui-btn weui-btn_primary" style="color: #fff; margin-top: 100px;"
				onclick="newDoChangePaw()">修改密码</a>

		</div>

		<script>
			var countdown = 60;
			// 修改密码
			function newDoChangePaw() {
				//获取输入框的各个输入值，进行判断
				var nowPassword, newPassword, newPassword2,phoneNumber,codeNumber;
				// nowPassword = $("#oldPass").val().trim();
				phoneNumber = $("#txt_phone").val().trim();
				codeNumber = $("#code_input").val().trim();
				newPassword = $("#mewPass").val().trim();
				newPassword2 = $("#mewPass_Again").val().trim();
				// if (isSpace(nowPassword)) {
				// 	msgInfo("原登录密码不能为空！");
				// 	return false;
				// }
				if (isSpace(phoneNumber)) {
					msgInfo("输入手机号码不能为空！");
					return false;
				}
				if(isSpace(codeNumber)){
					msgInfo("验证码不能为空！");
					return false;
				}
				if (isSpace(newPassword)) {
					msgInfo("新登录密码不能为空！");
					return false;
				}
				if (isSpace(newPassword2)) {
					msgInfo("确认新登录密码不能为空！");
					return false;
				}
				if (newPassword != newPassword2) {
					msgInfo("两次密码输入不一样！");
					return false;
				}
				var params = {
					"mobile": phoneNumber,
					"newPassword": newPassword,
					"smsCode":codeNumber,
					"confirmPassword":newPassword2
				};
				console.log(params);
				console.log(newPassword);
				console.log(newPassword2);
				newAjaxPost("/h5/userInfo/updatePassword", params, newDoChangePawOk);
				return false;
			}

			function newDoChangePawOk(jsonInfo) {
				if (jsonInfo.code == 1) {
					msgInfo("修改成功！");
					setTimeout(function(){
						goPage('inquiry_user_personal.htm')
					},2000)
				} else
					msgInfo(jsonInfo.msg);
			}

			//点击发送按钮后
			function noClick() {
				if (countdown == 0) {
					$('#v_container').text('重新发送')
					$('#v_container').removeClass("notClickn")
					countdown = 60;
					return;
				} else {
					$('#v_container').text('重新发送(' + countdown + ')')
					$('#v_container').addClass("notClickn")
					countdown--;
				}
				setTimeout(function () {
					noClick()
				}, 1000)
			}

			function check() {
				strUserName = $("#txt_phone").val().trim();
				var myreg = /^[1][0-9]{10}$/;
				if (strUserName.length == 11 && myreg.test(strUserName)) {
					let params = {
						"mobile": strUserName,
					}
					newAjaxPost("/h5/login/judgeUser", params, checkOk);
				}
			}

			function checkOk(jsonInfo) {
				if (jsonInfo.code == 1) {
					if (jsonInfo.data.list.length == 1 || (jsonInfo.data.list.length == 2 && jsonInfo.data.list[1] == 3)) {
						//单个角色
						roles = 1;
						role = jsonInfo.data.list[0]
						if (role == 1) { //用户
							$("#SMS").removeClass("disappear")
						} else if (role == 2) { //服务点
							$("#SMS").addClass("disappear")
						}
					} else if (jsonInfo.data.list.length >= 3) {
						// 用户和服务点都有
						roles = 2;
					}
				} else {
					msgInfo(jsonInfo.msg);
				}
			}
			//点击获取验证码
			function get_captcha() {
				strUserName = $("#txt_phone").val().trim();
				var myreg = /^[1][0-9]{10}$/;
				if (!myreg.test(strUserName)) {
					msgInfo("请输入正确的手机号码！");
					return false;
				} else {
					let params = {
						"mobile": strUserName,
						"type": 1
					}
					newAjaxPost("/h5/captcha/phoneCaptcha", params, get_captchaOk);
					return true;
				}
			}

			//获取验证码返回成功函数
			function get_captchaOk(jsonInfo) {
				console.log(jsonInfo);
				if (jsonInfo.code == 1) {
					noClick()
					msgInfo("已发送短信验证码,请注意查收！");
				} else {
					msgInfo(jsonInfo.msg);
				}
			}
		</script>
</body>

</html>